﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Advisor_RemoveTemplate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //The first time the page is loaded, get a list of all the templates and populate the list
        if (!IsPostBack)
        {
            if (Session["isAdmin"] == null || !(Boolean)Session["isAdmin"])
            {
                Page.Response.Redirect("Default.aspx");
            }
            List<Dictionary<String, Object>> templates = StoredProcedures.getTemplates();
            TemplateList.Items.Clear();
            foreach (Dictionary<String, Object> i in templates)
            {
                TemplateList.Items.Add(new ListItem(i["name"].ToString(), i["templateID"].ToString()));
            }
        }
    }
    protected void HomeButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Advisor/Default.aspx");
    }
    protected void HelpButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Advisor/Help.aspx");
    }
    protected void RemoveTemplateButton_Click(object sender, EventArgs e)
    {
        if (TemplateList.SelectedItem == null)
            return;
        StoredProcedures.removeTemplate(TemplateList.SelectedValue);
        TemplateList.Items.Remove(TemplateList.SelectedItem);
    }
}